import screens.screen
import pygame.display
from pygame.locals import *
from pygameExt import pygameext
class moveScreen(screens.screen.screeninherit):
    def __init__(self, screen, itemspos=[], background="", screenname=""):
        self.items=itemspos
        self.background=background
        self.screenname=screenname
        self.positionx = 0
        self.positiony = 0
        self.nextscene=0
        self.screen = screen
        self.square = 5
        
    def init(self):
        self.screen.fill((0,0,0))
        pygame.display.update()
        self.keylisteners = [screens.screen.keyListener(K_UP, self.key('up')), 
                        screens.screen.keyListener(K_DOWN, self.key('down')),
                        screens.screen.keyListener(K_LEFT, self.key('left')),
                        screens.screen.keyListener(K_RIGHT, self.key('right'))]
        if (self.background!=""):
            self.background = loadImage(self.background)
            self.screen.blit(self.background, (0,0))
        self.drawstuff(self.items)
        
    def key(self, key):
        self.npositionx=0
        self.npositiony=0
        if (key == 'up'):
            self.npositiony = 1
        elif (key=='down'):
            self.npositiony = -1
        elif (key=='left'):
            self.npositionx = -1
        elif (key=='down'):
            self.npositionx = 1
        else:
            return
        if (self.onsomething((self.positionx+self.npositionx,self.positiony+self.npositiony)) == False):
            self.positiony =+ self.npositiony
            self.positionx =+ self.npositionx
        if (self.positionx!=0) or (self.positiony!=0):
            self.updatepicture()
            
    def onsomething(self, position):
        for item in self.items:
            print "item"
            if (item.pos==position):
                return True
        
    def drawstuff(self,items):
        for item in items:
            if (item != 0):
                image=pygameext.loadImage(item.image)
                self.screen.blit(image, item.pos)
                
    def loop(self):
        return